package sy.controller;

import java.util.List;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sy.jackson.AppRepairMixin;
import sy.jackson.SysProjectMixin;
import sy.jackson.SysUnitMixin;
import sy.util.MessageObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import sy.model.AppRepair;
import sy.model.SysBuilding;
import sy.model.SysDivision;
import sy.model.SysProject;
import sy.model.SysUnit;
import sy.service.AppRepairServiceI;
import sy.service.SysBuildingServiceI;
import sy.service.SysDivisionServiceI;
import sy.service.SysProjectServiceI;
import sy.service.SysUnitServiceI;
/**
 * @Description: 首页
 * @param 
 * @author     :wjy
 * Create Date : 2017年7月26日 
 */
@Controller
@SessionAttributes("currAccount")
@RequestMapping("equipmentRepairController")
public class EquipmentRepairController {
	
	@Autowired
	private AppRepairServiceI appRepairService;
	
	private static final ObjectMapper objectMapper = new ObjectMapper();
	

	/************************** view controller ***************************/
	
	/**
	 * @Description: 首页视图
	 * @param 
	 * @author     :wjy
	 * Create Date : 2017年7月30日 
	 */
	@RequestMapping(value="/view")
	public String objectView(Model model){
		List<AppRepair> appRepairList = appRepairService.list();
		
		model.addAttribute("appRepairList",appRepairList);
		return "equipmentInfo/equipmentRepair";
	}
	
	/************************** data controller ***************************/
	
	/**
	 * @Description: 返回全部json数据
	 * @param 
	 * @author     :wjy
	 * Create Date : 2017年7月26日 
	 */
	@ResponseBody
	@RequestMapping(value = "/getAllData", method = RequestMethod.POST,produces={"text/html;charset=UTF-8"})
	private String getAllData(HttpServletResponse response) {
		objectMapper.addMixInAnnotations(AppRepair.class, AppRepairMixin.BasicInfo.class);
		List<AppRepair> appRepairList = appRepairService.list();
		try {
			return objectMapper.writeValueAsString(appRepairList);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "";
	}
	
}
